﻿using System;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Threading;

namespace D3crft.Windows.UserControls {

    public partial class ucDPSPreview : UserControl {

        Border oBorder;
        Grid oGrid;
        BlurEffect oBlur;
        Label oCharName;
        Label oCharDPS;
        DispatcherTimer oTimer;

        int iCounter;

        public ucDPSPreview() {
            InitializeComponent();

            oBorder = FindName("Border") as Border;
            oGrid = FindName("Grid") as Grid;
            oBlur = FindName("Blur") as BlurEffect;
            oCharName = FindName("CharName") as Label;
            oCharDPS = FindName("CharDPS") as Label;
            oTimer = new DispatcherTimer();

            oTimer.Interval = TimeSpan.FromMilliseconds(25.0);
            oTimer.Tick += new EventHandler(ev_oTimer_Tick);
        }


        public void UpdateInfo(string sCharName, string sCharDPS) {
            iCounter = 0;
            oGrid.Background = new SolidColorBrush(Color.FromArgb(255, 55, 105, 155));
            oBlur.Radius = 20.0;
            oCharName.Content = sCharName;
            oCharDPS.Content = sCharDPS;
            oTimer.Start();
        }

        private void ev_oTimer_Tick(object sender, EventArgs ea) {
            iCounter++;

            oGrid.Background = new SolidColorBrush(Color.FromArgb(255, (Byte)(55 + (20 * iCounter)), (Byte)(105 + (15 * iCounter)), (Byte)(155 + (10 * iCounter))));
            oBlur.Radius = (double)(20 - (iCounter * 2));
            if (iCounter == 10) {
                oTimer.Stop();
            }
        }


    }
}
